//
//  NRWMyMessageVC.m
//  NRWMall
//
//  Created by 张记 on 2018/6/4.
//  Copyright © 2018年 com.anpxd. All rights reserved.
//

#import "NRWMyMessageVC.h"
#import "NRWMyMessageCell.h"
#import "NRWCarPushMsgModel.h"
#import "NRWMySubscriptionVC.h"
#import "NRWMyCollectionVC.h"

@interface NRWMyMessageVC ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic, strong) UITableView *tableview;
@property(nonatomic, strong) NSArray *dataArray;



@end

@implementation NRWMyMessageVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationView setTitle:@"我的消息"];
    kSelfWeak;
    [NRWCarPushMsgModel getCacheModelArrCompleted:^(NSArray<NRWCarPushMsgModel *> *modelArr) {
        weakSelf.dataArray = modelArr;
    }];
    [self initTableview];
}
-(void)initTableview{
    kSelfWeak;
    self.tableview = [[UITableView alloc] init];
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
    self.tableview.backgroundColor = backColor();
    [self.tableview registerNib:[UINib nibWithNibName:@"NRWMyMessageCell" bundle:nil] forCellReuseIdentifier:@"NRWMyMessageCell"];
    self.tableview.estimatedRowHeight = 0;
    self.tableview.estimatedSectionHeaderHeight = 0;
    self.tableview.estimatedSectionFooterHeight = 0;
    self.tableview.tableFooterView = DPView();
    [self.view addSubview:self.tableview];
    [self.tableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.view).mas_offset(getNavHeight());
        make.left.right.bottom.equalTo(weakSelf.view);
    }];
    if (@available(iOS 11.0, *)) {
        self.tableview.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    
}
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    if (self.dataArray.count == 0) {
        [self.tableview showMaskViewWithTitle:@"暂无消息" imageName:@"default_empty" titleToImageMargin:42 canScroll:NO didClick:^{
            
        }];
    }
}

#pragma mark - DelegateMethod
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NRWCarPushMsgModel *model = self.dataArray[indexPath.row];
    NRWMyMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NRWMyMessageCell" forIndexPath:indexPath];
    cell.model = model;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    NRWCarPushMsgModel *model = self.dataArray[indexPath.row];

    return model.height;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NRWCarPushMsgModel *model = self.dataArray[indexPath.row];
    if ([model.iOSPath isEqualToString:@"favorite"]) {
        NRWMyCollectionVC *collectvc = [[NRWMyCollectionVC alloc] init];
        [self.navigationController pushViewController:collectvc animated:YES];
    }else if ([model.iOSPath isEqualToString:@"selectTemplate"]){
        NRWMySubscriptionVC *subscribeVc = [[NRWMySubscriptionVC alloc] init];
        [self.navigationController pushViewController:subscribeVc animated:YES];
    }
   
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
